package com.jial08.rabbitmqretry.component;

import com.jial08.rabbitmqretry.domain.QueueEnum;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * <p>类描述：生产消息。</p>
 *
 * @author jl
 * @version v1.0.0.1。
 * @since JDK1.8。
 * <p>创建日期：2020/12/8 下午10:29。</p>
 */
@Component
public class Producer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息
     */
    public void send() {
        Map<String, Object> message = new HashMap<>(4);
        message.put("id", UUID.randomUUID().toString());
        String tradeNo = "asdfdf3rtd";
        message.put("tradeNo", tradeNo);
        message.put("sendTime", new Date());
        rabbitTemplate.convertAndSend(QueueEnum.QUEUE_ORDER_PAY.getExchange(), QueueEnum.QUEUE_ORDER_PAY.getRouteKey(),
                message, new CorrelationData(tradeNo));
    }

}
